library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(p8105.datasets)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
data(nyc_airbnb)

nyc_airbnb = 
  nyc_airbnb %>% 
  mutate(rating = review_scores_location / 2) %>%
  select(
    neighbourhood_group, neighbourhood, rating, price, room_type, lat, long) %>%
  filter(
    !is.na(rating), 
    neighbourhood_group == "Manhattan",
    room_type == "Entire home/apt",
    price %in% 100:500)

make a scatterplot

Here’s a plotly scatterplot!

nyc_airbnb %>% 
  plot_ly(
    x = ~lat, y = ~long, type = "scatter", mode = "markers",
    color = ~price, alpha = 0.5
  )